﻿Type=Activity
Version=3.15
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Dim V_XM As String
	Dim V_CH As String
	Dim V_BHID As Int
	Dim V_KSRQ,V_JSRQ As String
	Dim V_YZFW As String
	
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Dim pnlBH As Panel
	Dim pnlYZ As Panel
	Dim scvYZ As ScrollView
	
	Dim FontSizeYZNR,FontSizeYZRQ As Float
	
	Dim HttpJobTool As HttpJob
	
	Dim lsYZRecords As List
	
	FontSizeYZNR = 16
	FontSizeYZRQ = 24
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormBHYZList")
	Activity.Title = "病人医嘱明细信息-"  & V_CH & " " &V_XM & "("&V_YZFW&")"
	
	pnlYZ = scvYZ.Panel
	
	InitLayOut
	
End Sub

Sub Activity_Resume
	RefreshData
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub InitLayOut
	RemoveAll
	
	pnlBH.Height = 0
	pnlYZ.Height = 0
	
	scvYZ.Top = pnlBH.Height
	scvYZ.Left = 0
	scvYZ.Width = 100%X
	scvYZ.Height = 100%y - scvYZ.Top	
End Sub

Sub RemoveAll
  For i = pnlYZ.NumberOfViews -1 To 0 Step -1
      pnlYZ.RemoveViewAt(i)
  Next
  pnlYZ.Height = 0
	
	For i = pnlBH.NumberOfViews -1 To 0 Step -1
		pnlBH.RemoveViewAt(i)	
	Next
End Sub

Sub ClearAllNR
	ClearBHNR
	ClearYZNR
End Sub

Sub ClearBHNR
	
End Sub

Sub ClearYZNR
  For i = pnlYZ.NumberOfViews -1 To 0 Step -1
      pnlYZ.RemoveViewAt(i)
  Next
  pnlYZ.Height = 0
	
End Sub

Sub RefreshData
	Dim sURL,sSession,sText,sBHID,sKSRQ,sJSRQ As String
	
	ClearAllNR
	
	sSession = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserSession)
	sBHID = PublicVar.GV_DesTool.Base64encrypt(V_BHID)
	
	sKSRQ = PublicVar.GV_DesTool.Base64encrypt(V_KSRQ)
	sJSRQ = PublicVar.GV_DesTool.Base64encrypt(V_JSRQ)
	
	sText = "Session=" & sSession & "&BHID=" & sBHID & "&KSRQ=" & sKSRQ & "&JSRQ=" & sJSRQ

	sURL = PublicVar.GetServerUrl&"/getbhyzinfo"
	HttpJobTool.Initialize("Job1",Me)
	HttpJobTool.PostString(sURL,sText)
	
	ProgressDialogShow("正在获取数据，请稍候...")	

End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "Job1" Then
				HttpJobSuccess(Job)
      End If
   Else
		HttpJobError(Job)
   End If
   Job.Release
End Sub

Sub HttpJobSuccess (Job As HttpJob) 
	Dim sResult,sCode,sData,sBHData,sJGData As String
	Dim mapResult As Map
	
	ProgressDialogHide
	
	sResult = Job.GetString.Trim
	
	PublicVar.GV_JSonTool.Initialize(sResult)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sCode = mapResult.Get("Code")
	If sCode<>"0" Then
		sResult = mapResult.Get("Message")
		ToastMessageShow("获取数据失败"&CRLF &sResult, True)	
		
		PublicVar.CheckSession(sCode)
		Return
	End If
	
	sData = mapResult.Get("Data")
	If sData ="" Then
		ToastMessageShow("获取数据失败"&CRLF &"返回的数据为空", True)	
		Return	
	
	End If
	
	sData = PublicVar.GV_DesTool.Base64decrypt(sData)
	PublicVar.GV_JSonTool.Initialize(sData)
	lsYZRecords = PublicVar.GV_JSonTool.NextArray
	SetYZInfo(lsYZRecords)	
	

End Sub

Sub HttpJobError (Job As HttpJob) 
	Dim sMsg As String
	ProgressDialogHide
	
	Log("Error: " & Job.ErrorMessage)
	sMsg = "获取病人医嘱信息失败."& CRLF & Job.ErrorMessage 
  ToastMessageShow(sMsg, True)
End Sub

Sub SetYZInfo(lsRecords As List)
	Dim iTop1,iHeight,iTextColor,iColor,iPnlHeight As Int
	Dim mapResult As Map
	Dim iMGROUPID,iYZZL,iYZXH,iState,iYZID,iYZNo,iRow As Int
	Dim sYZMC,sYF,sCS,sKYZRQ,sKYZYS,sYL,sYLDW,sYFADD,sYZRQ,sYZZL As String
	
	iHeight = PublicVar.GV_ListView_ItemHeight
	iTop1 = 5
	iPnlHeight = 0
	sYZRQ = ""
	iYZID = 0
	iYZNo = 0
	
	ClearYZNR
	
	For i = 0 To lsRecords.Size - 1 
		mapResult = lsRecords.Get(i)
		
		iMGROUPID = mapResult.Get("MGROUPID")
		iYZXH = mapResult.Get("XH")
		iYZZL = mapResult.Get("YZZL")		
		sYZMC = mapResult.Get("PRINTMC")
		sYF = mapResult.Get("YF")
		sCS = mapResult.Get("CS")	
		sKYZRQ = mapResult.Get("KYZRQ2")
		sKYZYS = mapResult.Get("KYZYS")	
		iState = mapResult.Get("STATE")
		sYFADD = mapResult.Get("YFADD")
		sYL = mapResult.Get("YL")
		sYLDW = mapResult.Get("YLDW")
		sYZZL = GetYZZLText(iYZZL)
		
		If sYZRQ<>sKYZRQ Then
			iPnlHeight = iPnlHeight + iHeight+10
			iTextColor = Colors.Blue
			iColor = Colors.DarkGray
			
			AddYZNR(sKYZRQ,0,iPnlHeight ,100%X,iHeight+10,iTextColor,iColor,Gravity.CENTER,FontSizeYZRQ)	
		
			iPnlHeight = iPnlHeight + 10
			sYZRQ = sKYZRQ
		End If
		
		
		If iYZID <> iMGROUPID Then
			iPnlHeight = iPnlHeight + iHeight
			iTextColor = Colors.Blue
			iRow = iYZNo Mod 2
			If iRow =0 Then
				iColor = Colors.LightGray
			Else
				iColor = Colors.White
			End If
			iTextColor = GetYZTextColor(iState)
			
			AddYZNR(iYZNo,0,iPnlHeight ,5%X,iHeight,iTextColor,iColor,Gravity.CENTER,FontSizeYZNR)	
			AddYZNR(sYZZL,5%X,iPnlHeight ,5%X,iHeight,iTextColor,iColor,Gravity.CENTER,FontSizeYZNR)
			'AddYZNR(sKYZYS,5%X,iPnlHeight ,5%X,iHeight,iTextColor,iColor,Gravity.CENTER,FontSizeYZNR)
			
			AddYZNR(sYZMC,10%X,iPnlHeight ,70%X,iHeight,iTextColor,iColor,Gravity.LEFT,FontSizeYZNR)	
			AddYZNR(sYL & sYLDW,70%X,iPnlHeight ,10%X,iHeight,iTextColor,iColor,Gravity.LEFT,FontSizeYZNR)	
			AddYZNR(sYF,80%X,iPnlHeight ,10%X,iHeight,iTextColor,iColor,Gravity.CENTER,FontSizeYZNR)	
			AddYZNR(sCS,90%X,iPnlHeight ,10%X,iHeight,iTextColor,iColor,Gravity.CENTER,FontSizeYZNR)
			
			iYZNo = iYZNo + 1
			iYZID = iMGROUPID
		Else
			iPnlHeight = iPnlHeight + iHeight
			AddYZNR("",0,iPnlHeight ,5%X,iHeight,iTextColor,iColor,Gravity.CENTER,FontSizeYZNR)	
			AddYZNR("",5%X,iPnlHeight ,5%X,iHeight,iTextColor,iColor,Gravity.CENTER,FontSizeYZNR)
			'AddYZNR("",5%X,iPnlHeight ,5%X,iHeight,iTextColor,iColor,Gravity.CENTER,FontSizeYZNR)
			
			AddYZNR(sYZMC,10%X,iPnlHeight ,70%X,iHeight,iTextColor,iColor,Gravity.LEFT,FontSizeYZNR)	
			AddYZNR(sYL & sYLDW,70%X,iPnlHeight ,10%X,iHeight,iTextColor,iColor,Gravity.LEFT,FontSizeYZNR)
			
			AddYZNR("",80%X,iPnlHeight ,10%X,iHeight,iTextColor,iColor,Gravity.CENTER,FontSizeYZNR)	
			AddYZNR("",90%X,iPnlHeight ,10%X,iHeight,iTextColor,iColor,Gravity.CENTER,FontSizeYZNR)			
		End If
		

	Next
	
	pnlYZ.Height = iPnlHeight + iHeight
	
End Sub

Sub AddYZNR(AText As String,ALeft As Int,ATop As Int,AWidth As Int,AHeight As Int, _
		ATextColor As Int,AColor As Int,AGravity As Int,AFonSize As Int )
	Dim lblSM As Label

	lblSM.Initialize("lblYZNR")
	lblSM.Text = AText
	lblSM.Gravity = AGravity
	lblSM.TextSize = AFonSize
	lblSM.Color = AColor
	lblSM.TextColor = ATextColor
	lblSM.Tag = 1

	pnlYZ.AddView(lblSM,ALeft,ATop,AWidth,AHeight)

End Sub

Sub GetYZZLText(AYZZL As Int) As String
	Select AYZZL
		Case 0
			Return "长"
		Case 1
			Return "临"
		Case 9,15
			Return "出"
		Case 16
			Return "中"			
	End Select	
End Sub

Sub GetYZTextColor(AState As Int) As Int

	Select Bit.AND(AState,15) 
		Case 0
			Return Colors.ARGB(100,128,0,0)	
		Case 1
			Return Colors.ARGB(100,0,0,255)	
		Case 2
			If Bit.AND(AState,2048) = 0 Then
				Return Colors.ARGB(100,0,0,128)	
			Else
				Return Colors.ARGB(100,128,128,128)	
			End If
	End Select
	
End Sub


